package com.isoft.hospital.service.Impl;

import com.isoft.hospital.common.ResponseData;
import com.isoft.hospital.dao.PatientDao;
import com.isoft.hospital.dao.PrescriptionDao;
import com.isoft.hospital.entity.Patient;
import com.isoft.hospital.entity.Prescription;
import com.isoft.hospital.service.PatientService;
import com.isoft.hospital.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientDao dao;

    @Override
    public ResponseData selectAll() {
        List<Patient> list = dao.selectAll();
        ResponseData responseData = new ResponseData();
        if (list != null) {
            responseData.setCode(0);
            responseData.setMsg("ok");
            responseData.setData(list);
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData insert(Patient patient) {
        int temp = dao.insert(patient);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData delete(int p_id) {
        int temp = dao.delete(p_id);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData update(Patient patient) {
        int temp = dao.update(patient);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData findById(int p_id) {
        Patient patient = dao.findById(p_id);
        ResponseData responseData = new ResponseData();
        if (patient!=null) {
            responseData.setCode(0);
            List<Patient> patients=new ArrayList<>();
            patients.add(patient);
            responseData.setMsg("ok");
            responseData.setData(patients);
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData findBypsf(String p_sf) {
        Patient patient = dao.findBypsf(p_sf);
        ResponseData responseData = new ResponseData();
        if (patient!=null) {
            responseData.setCode(0);
            List<Patient> patients=new ArrayList<>();
            patients.add(patient);
            responseData.setMsg("ok");
            responseData.setData(patients);
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

//    @Override
//    public ResponseData insertguahao(Patient patient) {
//        int temp = dao.insertguahao(patient);
//        ResponseData responseData = new ResponseData();
//        if (temp > 0) {
//            responseData.setCode(0);
//            responseData.setMsg("ok");
//        } else {
//            responseData.setCode(1);
//            responseData.setMsg("no");
//        }
//        return responseData;
//    }
}
